package com.msh.artascope.devcloud.service.api;

import com.msh.artascope.devcloud.client.po.ModuleReverseProxyPo;
import com.msh.artascope.devcloud.client.qo.ModuleReverseProxyQo;
import com.msh.artascope.devcloud.service.model.query.ModuleReverseProxyQueryVo;
import com.msh.artascope.devcloud.service.model.vo.ModuleReverseProxyVo;
import com.msh.artascope.devcloud.service.service.ModuleReverseProxyService;
import com.msh.artascope.interfaces.IAccountGet;
import com.msh.artascope.interfaces.ILoginAccount;
import com.msh.frame.client.common.Result;
import com.msh.frame.client.exception.BizException;
import com.msh.frame.client.validation.IDeleteVo;
import com.msh.frame.client.validation.IInsertVo;
import com.msh.frame.client.validation.IListVo;
import com.msh.frame.client.validation.IUpdateVo;
import com.msh.frame.web.base.BaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * 制品反向代理-api相关接口
 *
 * @author shihu
 * @email m-sh@qq.com
 */
@Tag(name = "制品反向代理-api相关接口")
@Slf4j
@RestController
@RequestMapping("/api/moduleReverseProxy")
public class ModuleReverseProxyApi extends
    BaseController<ModuleReverseProxyPo, ModuleReverseProxyQo> {

  @Resource
  private ModuleReverseProxyService moduleReverseProxyService;

  @Resource
  private IAccountGet accountGet;

  /**
   * 制品反向代理新增
   *
   * @param p
   * @return
   */
  @Operation(summary = "制品反向代理新增")
  @PostMapping("insert")
  public Result<Long> insert(
      @Validated({IInsertVo.class, Default.class}) @RequestBody ModuleReverseProxyVo p) {
    ILoginAccount loginAccount = accountGet.getLoginAccount();
    BizException.doThrowIfNull("无法获取登录账号信息", loginAccount);
    p.initLoginAccount(loginAccount);
    return Result.successReturn(moduleReverseProxyService.insertVo(p));
  }

  /**
   * 制品反向代理修改
   *
   * @param p
   * @return
   */
  @Operation(summary = "制品反向代理修改")
  @PostMapping("update")
  public Result<Void> update(
      @Validated({IUpdateVo.class, Default.class}) @RequestBody ModuleReverseProxyVo p) {
    ILoginAccount loginAccount = accountGet.getLoginAccount();
    BizException.doThrowIfNull("无法获取登录账号信息", loginAccount);
    p.initLoginAccount(loginAccount);
    moduleReverseProxyService.update(p);
    return Result.voidReturn();
  }


  /**
   * 制品反向代理删除
   *
   * @param p
   * @return
   */
  @Operation(summary = "制品反向代理删除")
  @PostMapping("delete")
  public Result<Void> delete(
      @Validated({IDeleteVo.class, Default.class}) @RequestBody ModuleReverseProxyPo p) {
    ILoginAccount loginAccount = accountGet.getLoginAccount();
    BizException.doThrowIfNull("无法获取登录账号信息", loginAccount);
    moduleReverseProxyService.deleteVo(p.getId(), loginAccount.getTenantId());
    return Result.voidReturn();
  }

  /**
   * 制品反向代理详情
   *
   * @param id
   * @return
   */
  @Operation(summary = "制品反向代理详情")
  @GetMapping("get")
  public Result<ModuleReverseProxyVo> get(
      @NotNull(message = "id不能为空") @RequestParam("id") Long id) {
    ILoginAccount loginAccount = accountGet.getLoginAccount();
    BizException.doThrowIfNull("无法获取登录账号信息", loginAccount);
    return Result.successReturn(moduleReverseProxyService.getVo(id, loginAccount.getTenantId()));
  }

  /**
   * 制品反向代理vo列表查询
   *
   * @param q
   * @return
   */
  @Operation(summary = "制品反向代理vo列表查询")
  @PostMapping("list")
  public Result<List<ModuleReverseProxyVo>> list(
      @Validated({IListVo.class}) @RequestBody ModuleReverseProxyQueryVo q) {
    ILoginAccount loginAccount = accountGet.getLoginAccount();
    BizException.doThrowIfNull("无法获取登录账号信息", loginAccount);
    q.initLoginAccount(loginAccount);
    return Result.successReturn(moduleReverseProxyService.listVo(q));
  }


  /**
   * 制品反向代理vo分页查询
   *
   * @param q
   * @return
   */
  @Operation(summary = "制品反向代理vo分页查询")
  @PostMapping("page")
  public Result<List<ModuleReverseProxyVo>> page(
      @Validated({IListVo.class}) @RequestBody ModuleReverseProxyQueryVo q) {
    ILoginAccount loginAccount = accountGet.getLoginAccount();
    BizException.doThrowIfNull("无法获取登录账号信息", loginAccount);
    q.initLoginAccount(loginAccount);
    return moduleReverseProxyService.pageVo(q);
  }
}
